home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / bs941029.tgz / bbsx-941029.tar / bbsx / sfstat.c < prev    next >
C/C++ Source or Header  |  1994-10-29  |  2KB  |  68 lines

  1. #ifndef __lint
  2. static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/sfstat.c,v 1.1 1994/06/01 22:21:32 dg1rtf Exp $";
  3. #endif
  4.  
  5. #define _HPUX_SOURCE
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <fcntl.h>
  10. #include <pwd.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <unistd.h>
  14.  
  15. #include "bbs.h"
  16. #include "bbs.hd"
  17.  
  18. const struct cmdtable cmdtable[1];
  19.  
  20. /* In sfstat.c: */
  21. int main(int argc, char **argv);
  22.  
  23. /*---------------------------------------------------------------------------*/
  24.  
  25. int main(int argc, char **argv)
  26. {
  27.  
  28.   FILE * fp, *fp1;
  29.   char  buf[1024];
  30.   char  host[80];
  31.   char  out[2048];
  32.   int  fd;
  33.   int  i;
  34.   struct index index;
  35.   struct passwd *pw;
  36.   unsigned long  cycle;
  37.  
  38.   cycle = (argc >= 2) ? atoi(argv[1]) : 0;
  39.   if (chdir(WRKDIR)) exit(1);
  40.   for (; ; ) {
  41.     if ((fd = open(INDEXFILE, O_RDONLY, 0644)) < 0) goto next;
  42.     if (lseek(fd, (long) (-sizeof(struct index )), 2) < 0) goto next;
  43.     if (read(fd, (char *) &index, sizeof(index)) != sizeof(index)) goto next;
  44.     if (!(fp = fopen(CONFIGFILE, "r"))) goto next;
  45.     if (cycle)
  46.       strcpy(out, "\033&a0y0C\033J");
  47.     else
  48.       *out = '\0';
  49.     while (fgets(buf, sizeof(buf), fp)) {
  50.       strlwc(buf);
  51.       if (sscanf(buf, "mbox:%s", host) < 1) continue;
  52.       if (!(pw = getpwnam(host))) continue;
  53.       sprintf(buf, "%s/" SEQFILE, pw->pw_dir);
  54.       if (!(fp1 = fopen(buf, "r"))) continue;
  55.       if (fscanf(fp1, "%d", &i) == 1)
  56.     sprintf(out + strlen(out), "%-6s  %5d\n", pw->pw_name, index.mesg - i);
  57.       fclose(fp1);
  58.     }
  59.     fclose(fp);
  60.     write(1, out, strlen(out));
  61. next:
  62.     if (!cycle) exit(0);
  63.     if (fd >= 0) close(fd);
  64.     sleep(cycle);
  65.   }
  66. }
  67.  
  68.